package com.cirnoworks.uhs.client;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.nio.ByteBuffer;

public class UHSSupport {
	public static void main(String[] args) {
		try {
			DatagramSocket socket = new DatagramSocket(4545);
			byte[] buf = new byte[65536];
			ByteBuffer buffer = ByteBuffer.wrap(buf);
			DatagramPacket packet = new DatagramPacket(buf, 0);
			while (true) {
				packet.setLength(65536);
				socket.receive(packet);
				buffer.clear();
				long value = buffer.getLong();
				System.out.println("Received " + packet.getAddress() + ":"
						+ packet.getPort() + " " + value);
				buffer.clear();
				buffer.putLong(value + 1);
				buffer.flip();
				packet.setLength(buffer.remaining());
				socket.send(packet);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
